<!DOCTYPE html>
<html  xmlns:th="http://www.thymeleaf.org">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>修改用户</title>
    <link href="css/style.css" rel="stylesheet" type="text/css" />

</head>
<body>

<div class="formbody">

    <div class="formtitle">
        <span th:if="${model.id}==null">添加用户</span>
        <span th:if="${model.id}!=null">编辑用户</span>
    </div>


    <ul class="forminfo">
        <li><label>登录名</label>
            <input type="text" id="txtLoginName" name="txtLoginName" th:value="${model.phone}" class="dfinput" tyle="width:200px" />
        </li>
        <li><label>密码</label>
            <input type="text" id="txtPassword" name="txtPassword" th:value="${model.password}" class="dfinput" tyle="width:200px" />
        </li>





        <li><label>&nbsp;</label>
            <input type="button" id="btnSave" class="btn" value="保存" />
            <input type="hidden" id="hiddAdminId" th:value="${model.id}" />
        </li>
    </ul>
</div>


</body>
<script type="text/javascript" src="js/jquery.js"></script>
<link href="plugin/artDialog/artDialog/skins/blue.css" rel="stylesheet" />
<script src="plugin/artDialog/artDialog/artDialog.min.js" type="text/javascript"></script>
<script src="plugin/artDialog/artDialog/artDialog.plugins.min.js" type="text/javascript"></script>
<script src="plugin/artDialog/dialog.js" type="text/javascript"></script>
<script>
    /*<![CDATA[*/
    function save(id,userName, pwd) {
        if (id){
            $.ajax({
                url: 'editUser',
                type: 'POST',
                data: {
                    'id' :id,
                    'phone':userName,
                    'password':pwd,
                },
                dataType: 'json',
                success: function (data) {
                    if (data.status == '0') {
                        showNotice('保存成功');
                        parent.location.reload();
                    } else {
                        showNotice(data.msg);
                    }
                }
            });}
        else {
            $.ajax({
                url: 'createUser',
                type: 'POST',
                data: {
                    'phone': userName,
                    'password': pwd,
                },
                dataType: 'json',
                success: function (data) {
                    if (data.status == '0') {
                        showNotice('保存成功');
                        parent.location.reload();
                    } else {
                        showNotice(data.msg);
                    }
                }
            });
        }
    }

    $(function () {
        $('#btnSave').click(function () {
            var id = $('#hiddAdminId').val();
            var userName = $('#txtLoginName').val();
            var pwd = $('#txtPassword').val();

            if (userName == '' || pwd == '') {
                alert('请填写完整信息');
                return false;
            }

            save(id,userName, pwd);
        });
    });
    /*]]>*/
</script>
</html>